package org.zwy.gradetrack.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.zwy.gradetrack.entity.GraduationRequirementAchievement;
import org.zwy.gradetrack.vo.GraduationRequirementAchievementVo;

import java.util.List;

/**
 * 毕业要求达成度Mapper接口
 */
@Mapper
public interface GraduationRequirementAchievementMapper extends BaseMapper<GraduationRequirementAchievement> {
    @Select("SELECT DISTINCT evaluation_year FROM graduation_requirement_achievement ORDER BY evaluation_year DESC")
    List<Integer> selectEvaluationYears();

    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "indicatorId", column = "indicator_id"),
        @Result(property = "directEvaluation", column = "direct_evaluation"),
        @Result(property = "graduateSelfEval", column = "graduate_self_eval"),
        @Result(property = "internshipEval", column = "internship_eval"),
        @Result(property = "teacherEval", column = "teacher_eval"),
        @Result(property = "comprehensiveScore", column = "comprehensive_score"),
        @Result(property = "isAchieved", column = "is_achieved"),
        @Result(property = "evaluationYear", column = "evaluation_year"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "updateTime", column = "update_time"),
        @Result(property = "indicatorName", column = "indicatorName")
    })
    @Select("<script>" +
            "SELECT " +
            "gra.id, gra.indicator_id, gra.direct_evaluation, gra.graduate_self_eval, " +
            "gra.internship_eval, gra.teacher_eval, gra.comprehensive_score, " +
            "gra.is_achieved, gra.evaluation_year, gra.create_time, gra.update_time, " +
            "i.indicator_name AS indicatorName " +
            "FROM graduation_requirement_achievement gra " +
            "LEFT JOIN indicator i ON gra.indicator_id = i.id " +
            "<where>" +
            "  <if test=\"evaluationYear != null\">AND gra.evaluation_year = #{evaluationYear}</if>" +
            "</where>" +
            "ORDER BY gra.evaluation_year DESC, gra.indicator_id ASC" +
            "</script>")
    List<GraduationRequirementAchievementVo> selectAchievementVos(Integer evaluationYear);
} 